﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using COM.Rights.Model;
using COM.Rights.BLL;

public partial class FrontPages_UserControl_NewsTop : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) {
            InitNews();
        }
    }

    public string StyleName
    {
        get
        {
            return CssControler.GetCssFileNameByHost(HostName);
        }
    } 

    private string _HostName;
    public string HostName
    {
        get
        {
            if (StringHelper.FormatObjToString(ViewState["HostName"]) != string.Empty)
            {
                return StringHelper.FormatObjToString(ViewState["HostName"]);
            }
            else if (!string.IsNullOrEmpty(hidHostName.Value))
            { ViewState["HostName"] = hidHostName.Value; return hidHostName.Value; }

            return this._HostName;
        }
        set
        {
            ViewState["HostName"] = value;
        }
    }



    protected void InitNews() {
        BdNews _BdNews = new BdNews();
        repNewsTop3.DataSource = _BdNews.GetDataTable(string.Format("SELECT TOP 3 News_ID,NewsTitle,remark NewsSummary FROM dbo.bdNews(NOLOCK) WHERE HostName LIKE '%{0}%' AND IsDelete = 0 AND  IsHeaderLine = 1 AND IsPublish = 1 ORDER BY CreateDate DESC", HostName));
        //repNewsTop3.DataSource = _BdNews.GetTop(3, "News_ID,NewsTitle,SUBSTRING(Contents,1,60) NewsSummary", "IsHeaderLine = 1", "CreateDate DESC", null);

        repNewsTop3.DataBind();
    }

}